﻿//using System;
//using System.Collections.Generic;
//using System.Diagnostics;
//using System.Linq;
//using System.Web;
//using System.Web.Mvc;
//using Contrib.AppFabric.Configuration;
//using Contrib.Cache.Services;
//using Microsoft.ApplicationServer.Caching;
//using Orchard.UI.Admin;

//namespace Contrib.AppFabric.Controllers {
//    [Admin]
//    public class TestController : Controller {
//        private readonly ICacheService _cacheService;
//        private readonly IAppFabricClient _client;
//        private readonly DataCache _entries;

//        public TestController(ICacheService cacheService, IAppFabricClient client) {
//            _cacheService = cacheService;
//            _client = client;

            
//        }

//        public ActionResult Index() {
//            TestIndexViewModel viewModel = new TestIndexViewModel();

//            viewModel.CacheItemConfiguration = new TestCacheItemConfigurationModel();
//            viewModel.CacheItemConfiguration.DataCacheProtectionLevel = DataCacheProtectionLevel.None;
//            viewModel.CacheItemConfiguration.DataCacheSecurityMode = DataCacheSecurityMode.None;

//            viewModel.CacheItemConfiguration.ServerName = Environment.MachineName;
//            viewModel.CacheItemConfiguration.ServerPort = 22233;

//            return View(viewModel);
//        }

//        [HttpPost]
//        public ActionResult Index(TestIndexViewModel viewModel) {
//            viewModel.Messages = new List<string>();

//            try {
//                var servers = new List<DataCacheServerEndpoint>(1);

//                servers.Add(new DataCacheServerEndpoint(viewModel.CacheItemConfiguration.ServerName, viewModel.CacheItemConfiguration.ServerPort));

//                var security = new DataCacheSecurity(viewModel.CacheItemConfiguration.DataCacheSecurityMode, viewModel.CacheItemConfiguration.DataCacheProtectionLevel);

//                DataCacheClientLogManager.ChangeLogLevel(TraceLevel.Off);

//                //Create cache configuration
//                var configuration = new DataCacheFactoryConfiguration {
//                    Servers = servers,
//                    LocalCacheProperties = new DataCacheLocalCacheProperties(),
//                    SecurityProperties = security,
//                    MaxConnectionsToServer = 1
//                };

//                var myCacheFactory = new DataCacheFactory(configuration);

//                viewModel.Messages.Add(string.Format("Connected to {0}", viewModel.CacheItemConfiguration.ServerName));
            
//                var cache = myCacheFactory.GetDefaultCache();

//                viewModel.Messages.Add(string.Format("Simple PUT GET starts"));
//                cache.Put("test", new object());
//                object foo = cache.Get("test");
//                viewModel.Messages.Add(string.Format("Simple PUT GET ends"));
//            }
//            catch (Exception exception) {
//                viewModel.Messages.Add(exception.ToString());
//            }
//            return View(viewModel);
//        }
//    }

//    public class TestIndexViewModel {
//        public TestCacheItemConfigurationModel CacheItemConfiguration { get; set; }

//        public IList<string> Messages { get; set; }
//    }

//    public class TestCacheItemConfigurationModel {
//        public string ServerName { get; set; }
//        public int ServerPort { get; set; }

//        public DataCacheSecurityMode DataCacheSecurityMode { get; set; }
//        public DataCacheProtectionLevel DataCacheProtectionLevel { get; set; }
//    }
//}